package ly.gupao.edu.threaddemo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SequentialControl {

    private static ExecutorService executorService = Executors.newSingleThreadExecutor();

    public static void main(String[] args) throws InterruptedException {

        /**
         * 创建三个线程
         */
        Thread thread1 = new Thread(){

            @Override
            public void run() {
                System.out.println("thread1 ！！！");
            }
        };
        Thread thread2 = new Thread(){

            @Override
            public void run() {
                System.out.println("thread2 ！！！");
            }
        };
        Thread thread3 = new Thread(){

            @Override
            public void run() {
                System.out.println("thread3 ！！！");
            }
        };


        /**
         * 代码中顺序执行三个线程，观察执行顺序
         */

        /**
         * 线程顺序执行方法一
         */
        thread1.start();
        thread1.join();
        thread2.start();
        thread2.join();
        thread3.start();
        thread3.join();


        /**
         * 线程顺序执行二
         */
        executorService.submit(thread1);
        executorService.submit(thread2);
        executorService.submit(thread3);
        executorService.shutdown();


        Thread.yield();
    }
}
